package com.hongdee.common.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;

/**
 * Created by Liu XiaoLong
 * Date: 2017/11/2.
 * Remark: 图片操作
 */
public final class ImageUtils {

    private ImageUtils(){

    }

    /**
     * @Name: 获取文件流
     * @Author: Liu XiaoLong
     * @Date: 2017/11/2 15:24
     * @Remark:
     */
    public static FileInputStream getFileInputStream(MultipartFile image) throws Exception{
        return (FileInputStream) image.getInputStream();
    }

    /**
     * @Name: 通过路径获取文件流
     * @Author: Liu XiaoLong
     * @Date: 2017/11/2 15:26
     * @Remark:
     */
    public static FileInputStream getFileInputStream(String path) throws Exception {
        return new FileInputStream(new File(path));
    }

    /**
     * @Name: 获取输出流输出
     * @Author: Liu XiaoLong
     * @Date: 2017/11/2 15:30
     * @Remark:
     */
   /* public static void outImage(InputStream in, String outPath) throws Exception{
        File file = new File(outPath);
        String path = outPath.substring(0, outPath.lastIndexOf("/"));
        if (!file.exists()) {
            new File(path).mkdir();
        }
        FileOutputStream fos;
        fos = new FileOutputStream(file);
        int len = 0;
        byte[] buf = new byte[1024];
        while ((len = in.read(buf)) != -1) {
            fos.write(buf, 0, len);
        }
        fos.flush();
        if (null != fos) {
            fos.close();
        }

    }*/



}
